package com.zhuiyun.project.api.physician.controller;

import com.zhuiyun.project.annotation.OptLog;
import com.zhuiyun.project.api.filemanage.service.FileManageService;
import com.zhuiyun.project.api.physician.entity.DoctorAudit;
import com.zhuiyun.project.api.physician.model.AppPhysicianModel;
import com.zhuiyun.project.api.physician.service.PhysicianService;
import com.zhuiyun.project.common.errorCode.CommonException;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.util.constants.CommonConstants;
import com.zhuiyun.project.util.pageUtil.PageRequest;
import com.zhuiyun.project.util.pageUtil.PageResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("physician")
@CrossOrigin
public class PhysicianController {
    @Autowired
    FileManageService fileManageService;
    @Autowired
    PhysicianService physicianService;

    /**
     * @param appPhysicianModel
     * @Author kdj
     * @Description 申请成为医师
     * @Date 2023/8/3 15:16
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @PostMapping("/insertPhysician")
    public CommonResult insertPhysician(@RequestBody AppPhysicianModel appPhysicianModel) {
        return physicianService.insertPhysician(appPhysicianModel);
    }


    /**
     * @param userId
     * @Author kdj
     * @Description 获取医师的个人信息
     * @Date 2023/8/3 16:15
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/getPhyInfo")
    public CommonResult getPhyInfo(int userId) {
        return physicianService.getPhyInfo(userId);
    }

    /**
     * 医师审核查询
     *
     * @return com.zhuiyun.project.common.response.CommonResult
     * @author 温
     * @date 2023/6/8 10:31
     * @parameter []
     */
    @GetMapping("/physicianList")
    @ApiOperation(value = "成为医师审核查询")
    @OptLog(modular = "医师审核", type = CommonConstants.SELECT, describe = "成为医师审核查询")
    public CommonResult physicianList(String doctorName, PageRequest pageRequest) {
        PageResult AppPhysicians = physicianService.physicianList(doctorName, pageRequest);
        return CommonResult.ok(AppPhysicians);
    }


    /**
     * 医师管理查询
     *
     * @return com.zhuiyun.project.common.response.CommonResult
     * @author 温
     * @date 2023/6/9 16:07
     * @parameter [nickName, pageRequest]
     */
    @GetMapping("/PhysicianListState")
    @ApiOperation(value = "医师信息查询")
    @OptLog(modular = "医师管理", type = CommonConstants.SELECT, describe = "医生信息查询")
    public CommonResult PhysicianListState(String queryUserName, PageRequest pageRequest) {
        PageResult pageResult = physicianService.PhysicianListState(queryUserName, pageRequest);
        return CommonResult.ok(pageResult);
    }


    /**
     * @param file              头像
     * @param file1             个人图片
     * @param file2             执业证书
     * @param appPhysicianModel
     * @Author kdj
     * @Description 修改医师信息
     * @Date 2023/8/5 10:38
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @PostMapping("/updatePhy")
    @ApiOperation(value = "修改医师信息")
    @OptLog(modular = "医师管理", type = CommonConstants.UPDATE, describe = "修改医师师信息")
    public CommonResult appPhysicianRejectAdd(MultipartFile file, MultipartFile file1, MultipartFile file2, AppPhysicianModel appPhysicianModel) {
        return physicianService.updatePhy(file, file1, file2, appPhysicianModel);
    }

    /**
     * @param file              头像
     * @param file1             个人图片
     * @param file2             执业证书
     * @param appPhysicianModel
     * @Author ys
     * @Description 修改医师信息
     * @Date 2023/8/5 10:38
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @PostMapping("/updateAppPhy")
    @ApiOperation(value = "修改医师信息")
    @OptLog(modular = "医师管理", type = CommonConstants.UPDATE, describe = "修改医师师信息")
    public CommonResult appAppPhysicianRejectAdd(MultipartFile file, MultipartFile file1, MultipartFile file2, @RequestBody AppPhysicianModel appPhysicianModel) {
        return physicianService.updatePhy(file, file1, file2, appPhysicianModel);
    }
    /**
     * @param file              头像
     * @param appPhysicianModel
     * @Author ys
     * @Description 修改医师信息
     * @Date 2023/8/5 10:38
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @PostMapping("/updateUser")
    @ApiOperation(value = "修改用户信息")
    @OptLog(modular = "用户管理", type = CommonConstants.UPDATE, describe = "修改用户信息")
    public CommonResult appAppUserRejectAdd(MultipartFile file, @RequestBody AppPhysicianModel appPhysicianModel) {
        return physicianService.updateUser(file, appPhysicianModel);
    }

    @PostMapping("/addPhy")
    @ApiOperation(value = "添加医师信息")
    @OptLog(modular = "医师管理", type = CommonConstants.ADD, describe = "添加医师信息")
    public CommonResult addPhy(MultipartFile file, MultipartFile file1, MultipartFile file2, AppPhysicianModel appPhysicianModel) {
        return physicianService.addPhy(file, file1, file2, appPhysicianModel);
    }
  /**
  * @Author kdj
  * @Description 审核通过医师
  * @Date 2023/8/5 21:41
  * @Return com.zhuiyun.project.common.response.CommonResult
  * @param doctorAudit
  */
    @PostMapping("/requestOk")
    @ApiOperation(value = "审核通过医师")
    @OptLog(modular = "医师管理", type = CommonConstants.UPDATE, describe = "审核通过医师")
    public CommonResult requestOk(@RequestBody DoctorAudit doctorAudit) {
        return physicianService.requestOk(doctorAudit);
    }
    /**
     * @Author kdj
     * @Description 审核通过医师
     * @Date 2023/8/5 21:41
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param doctorAudit
     */
    @PostMapping("/requestNo")
    @ApiOperation(value = "审核不通过医师")
    @OptLog(modular = "医师管理", type = CommonConstants.UPDATE, describe = "审核不通过医师")
    public CommonResult requestNo(@RequestBody DoctorAudit doctorAudit) {
        return physicianService.requestNo(doctorAudit);
    }


    /**
     * 医师删除
     *
     * @return com.zhuiyun.project.common.response.CommonResult
     * @author 温
     * @date 2023/6/11 20:54
     * @parameter [id]
     */
    @DeleteMapping("/PhysicianUpdate")
    @ApiOperation(value = "医师删除")
    @OptLog(modular = "医师管理", type = CommonConstants.DELETE, describe = "医师删除")
    public CommonResult PhysicianUpdate(int id) {
        int i = physicianService.PhysicianUpdate(id);
        return CommonResult.ok(i);
    }

    /**
     * @param id
     * @Author ys
     * @Description 根据医师id获取userid
     * @Date 2023/8/3 16:15
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/getPhysicianUserid")
    public CommonResult getPhysicianUserid(int id) {
        int physicianUserid = physicianService.getPhysicianUserid(id);
        return CommonResult.ok(physicianUserid);
    }
}




